/*
 * mymonitor.h -- user implemented monitor library. 
 */

#ifndef MYMONITOR_H
#define MYMONITOR_H

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#include "mythread.h"

/* Structure to implement the monitor functions */
typedef struct monitor {
	unsigned long int locked; /* Indicates whether there is someone in the monitor or not, 1 or 0 respectively */
	int signalReady; /* Flag that indicates monitor_exit needs to signal a thread once that thread is done with the monitor */
	int broadcastReady; /* Flag that indicates monitor_exit needs to signal all threads once that thread is done with the monitor */
} monitor_t;

/*
 * monitor_init - initializing the monitor
 */
int monitor_init(monitor_t *m);

 /*
 * monitor_enter - entering the monitor
 */
int monitor_enter(monitor_t *m);

/*
 * monitor_exit exiting the monitor
 */
int monitor_exit(monitor_t *m);
 
/*
 * monitor_destroy - destroying the monitor
 */
int monitor_destroy(monitor_t *m);

/*
 * monitor_signal 
 */
int monitor_signal(monitor_t *m);
 
/*
 * monitor_broadcast 
 */
int monitor_broadcast(monitor_t *m);
 
/*
 * monitor_wait 
 */
int monitor_wait(monitor_t *m);

#endif /* MYMONITOR_H */
